<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>修改管理员权限</title>

    <!-- 引入Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- 自定义样式 -->
    <style>
        body {
            background-color: #f4f7fc;
            font-family: Arial, sans-serif;
            display: flex;
            min-height: 100vh;
            margin: 0;
        }

        /* 侧边栏样式 */
        .sidebar {
            width: 250px;
            background-color: #007bff;
            color: white;
            height: 100vh;
            position: fixed;
            top: 0;
            left: 0;
            padding-top: 20px;
            box-shadow: 2px 0px 5px rgba(0, 0, 0, 0.1);
        }

        .sidebar h2 {
            text-align: center;
            margin-bottom: 20px;
            font-size: 20px;
        }

        .sidebar a {
            display: block;
            padding: 12px;
            color: white;
            text-decoration: none;
            font-size: 16px;
            border-radius: 4px;
            margin: 5px 0;
        }

        .sidebar a:hover {
            background-color: #0056b3;
        }

        /* 页面主内容部分 */
        .main-content {
            margin-left: 250px;
            padding: 30px;
            flex-grow: 1;
        }

        .card {
            border: none;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            padding: 30px;
            margin-top: 20px;
            background-color: #fff;
            border-radius: 8px;
            transition: all 0.3s ease;
        }

        .card:hover {
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
        }

        h1, h3, h4 {
            color: #333;
            font-weight: bold;
        }

        h1 {
            font-size: 28px;
            margin-bottom: 20px;
        }

        h3 {
            font-size: 22px;
            margin-top: 20px;
            margin-bottom: 15px;
        }

        h4 {
            font-size: 18px;
            margin-bottom: 10px;
        }

        .message, .error {
            padding: 10px;
            margin-bottom: 20px;
            border-radius: 4px;
        }

        .message {
            background-color: #d4edda;
            color: #155724;
        }

        .error {
            background-color: #f8d7da;
            color: #721c24;
        }

        .permissions-list {
            list-style-type: none;
            padding: 0;
            margin: 0;
        }

        .permissions-list li {
            background-color: #f9f9f9;
            margin-bottom: 10px;
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 4px;
        }

        .permissions-options div {
            margin-bottom: 12px;
            font-size: 16px;
        }

        .permissions-options input[type="checkbox"] {
            margin-right: 10px;
        }

        .btn-custom {
            background-color: #007bff;
            color: white;
            border: none;
            padding: 12px 25px;
            border-radius: 5px;
            font-size: 1rem;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        .btn-custom:hover {
            background-color: #0056b3;
        }

        .back-link {
            display: inline-block;
            margin-top: 20px;
            text-align: center;
            color: #007bff;
            font-size: 1.1rem;
        }

        .back-link:hover {
            text-decoration: underline;
            color: #0056b3;
        }

        .form-control {
            margin-bottom: 15px;
        }

        .form-label {
            font-weight: bold;
        }

        .form-group {
            margin-bottom: 25px;
        }
    </style>
</head>

<body>

<!-- 侧边栏 -->
<div class="sidebar">
    <h2>超级管理员控制台</h2>
    <a href="/superAdmin/achievementReview">科研成果审核</a>
    <a href="/superAdmin/users">用户管理</a>
    <a href="/superAdmin/permissions/management">权限管理</a>
    <a href="/superAdmin/articleReview">文章审核</a>
    <a href="/logout">退出登录</a>
</div>

<!-- 页面主内容 -->
<div class="main-content">
    <div class="card">
        <h1>修改管理员权限</h1>

        <!-- 显示成功和错误消息 -->
        <c:if test="${not empty message}">
            <div class="message">${message}</div>
        </c:if>

        <c:if test="${not empty error}">
            <div class="error">${error}</div>
        </c:if>

        <!-- 显示管理员基本信息 -->
        <h3>管理员信息</h3>
        <p><strong>用户名：</strong>${user.nickname}</p>
        <p><strong>姓名：</strong>${user.name}</p>
        <p><strong>邮箱：</strong>${user.email}</p>

        <!-- 权限修改表单 -->
        <h3>修改权限</h3>
        <form action="<c:url value='/superAdmin/users/${user.userId}/modifyPermissions' />" method="post">

            <!-- 显示已拥有的权限 -->
            <h4>已拥有的权限：</h4>
            <ul class="permissions-list">
                <c:forEach var="permissionId" items="${userPermissions}">
                    <li>
                        <c:forEach var="permission" items="${allPermissions}">
                            <c:if test="${permission.value == permissionId}">
                                ${permission.name}
                            </c:if>
                        </c:forEach>
                    </li>
                </c:forEach>
            </ul>

            <!-- 选择要添加/修改的权限 -->
            <h4>选择要添加或取消的权限：</h4>
            <div class="permissions-options">
                <c:forEach var="permission" items="${allPermissions}">
                    <div>
                        <input type="checkbox" name="permissionTypes" value="${permission.value}"
                               <c:if test="${userPermissions.contains(permission.value)}">checked</c:if>
                        />
                            ${permission.name}
                    </div>
                </c:forEach>
            </div>

            <br>
            <button type="submit" class="btn-custom">保存权限</button>
        </form>

        <!-- 返回权限管理界面链接 -->
        <a href="<c:url value='/superAdmin/permissions/management' />" class="back-link">返回权限管理界面</a>
    </div>
</div>

<!-- 引入Bootstrap 5 JS 和依赖 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>

</body>

</html>
